package com.baizhi.springboot.service.impl;

import com.baizhi.springboot.dao.RoleDao;
import com.baizhi.springboot.entity.Resource;
import com.baizhi.springboot.entity.Role;
import com.baizhi.springboot.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleDao roleDao;
    @Override
    public Map selectRoleByPage(Integer page, Integer limit) {
        Integer offset=(page-1)*limit;
        List<Role> roles = roleDao.selectRoleByPage(offset, limit);
        Integer count = roleDao.selectCount();
        /* "code": 0,
          "msg": "",
          "count": 1000,
          "data": [{}, {}]*/
        HashMap<Object, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", count);
        map.put("data", roles);
        return map;
    }

    @Override
    public Set<String> selectRoleNameByUserId(Integer userId) {
        return roleDao.selectRoleNameByUserId(userId);
    }

    @Override
    public Set<String> selectRoleIdByUserId(Integer userId) {
        return roleDao.selectRoleIdByUserId(userId);
    }

    @Override
    public void deleteRole(Integer id) {
        roleDao.deleteRole(id);
    }

    @Override
    public void updateRole(Role role) {
        roleDao.updateRole(role);
    }

    @Override
    public void insertRole(Role role) {
        roleDao.insertRole(role);
    }

    @Override
    public Role selectOneRole(Integer id) {
        return roleDao.selectOneRole(id);
    }


}
